/**
 *  Copyright(C) 2007 Juri Strumpflohner
 *  All rights reserved
 *
 *  Created: 18.07.2007
*/

package org.aroundme.sandbox;

import java.util.Date;
import java.util.List;

import org.apache.log4j.PropertyConfigurator;
import org.aroundme.model.DateManager;
import org.aroundme.model.Place;
import org.aroundme.utility.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class TestHibernate {

	public static void main(String[] args) {
		PropertyConfigurator.configure("./conf/log4j.properties");
//		HibernateUtil.setTestFactory();
		
//		List<Place> list = retrieveExpiredPlaces();
//		for (Place place : list) {
//			System.out.println(place.getTitle() + " expired: " + new DateManager().getSimpleDateFormatter().format(place.getExpiryDate()));
//		}

	}
	
	public static List<Place> retrieveExpiredPlaces(){
		List<Place> result = null;
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		s.beginTransaction();
		try{
			Criteria c = s.createCriteria(Place.class);
			c.add(Restrictions.lt("expiryDate", new Date()));
			result = c.list();
		}catch(HibernateException e){
			e.printStackTrace();
			s.getTransaction().rollback();
		}
		
		return result;
	}

}
